<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>商城首页</title>
    <%@ include file="/page/menu/head.jsp" %>
    <script>
        function addToCart(dom){
            var judge=dom.name;

            if("true"==judge)
            {
                alert("需要先登录才能购物哦~");
            }


            else window.location.href = "sale/ItemServlet?action=GetItem&id=" + dom.value;

        }
    </script>
</head>
<body>

<div id="header">
    <span class="wel_word">kangkang的电商网站</span>
    <%@include file="/page/menu/login_menu.jsp"%>

</div>
<div id="main">
    <div id="book">
        <div style="text-align: center">
            <c:if test="${empty sessionScope.cart.items}">
                <%--购物车为空的输出--%>
                <div>
                    <span style="color: red">当前购物车为空</span>
                </div>
            </c:if>
            <c:if test="${not empty sessionScope.cart.items}">
                <%--购物车非空的输出--%>
                <span>您的购物车中有 ${sessionScope.cart.totalCount} 件商品</span>
                <div>
                    您刚刚将<span style="color: red">${sessionScope.lastName}</span>加入到了购物车中
                </div>
            </c:if>
        </div>

        <c:forEach items="${requestScope.page.items}" var="item">
            <div class="b_list">
                <div class="img_div">
                    <img class="item_img" alt="" src="${item.imgPath}" />
                </div>
                <div class="item_info">
                    <div class="item_name">
                        <span class="sp1">商品名称:</span>
                        <span class="sp2">${item.name}</span>
                    </div>
                    <div class="item_price">
                        <span class="sp1">价格:</span>
                        <span class="sp2">￥${item.price}</span>
                    </div>
                    <div class="item_sales">
                        <span class="sp1">销量:</span>
                        <span class="sp2">${item.sales}</span>
                    </div>
                    <div class="item_amount">
                        <span class="sp1">库存:</span>
                        <span class="sp2">${item.stock}</span>
                    </div>
                    <div class="item_add">
                        <button onclick="addToCart(this)" value="${item.id}" name="${empty sessionScope.user}" class="addToCart" >加入购物车</button>
                    </div>
                </div>
            </div>
        </c:forEach>
    </div>

</div>
<%@include file="/page/menu/page_nav.jsp"%>
</body>
</html>
